package com.project.housesalesystem.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
<<<<<<< HEAD
=======
import com.project.housesalesystem.bean.House;
>>>>>>> 66dcee4e153c16ef05fd0c7e1ed9f414a0bf0bc9
import com.project.housesalesystem.bean.Users;
import com.project.housesalesystem.common.PageResult;
import com.project.housesalesystem.common.Results;
import com.project.housesalesystem.service.UsersService;
<<<<<<< HEAD
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
=======
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
>>>>>>> 66dcee4e153c16ef05fd0c7e1ed9f414a0bf0bc9
import java.util.List;
import java.util.Map;

@RequestMapping("user")
@RestController
public class UsersController {
    @Resource
    private UsersService userService;
    /**
     * 新增
     */
    @PostMapping("/add")
    public Results add(@ModelAttribute Users user){
        userService.save(user);
        return Results.ok();
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Results deleteById(@PathVariable Integer id) {
        userService.removeById(id);
        return Results.ok();
    }


    /**
     * 修改
     */
    @PutMapping("/update")
    public Results updateById(@RequestBody Users user) {
        userService.updateById(user);
        return Results.ok();
    }


    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Results selectById(@PathVariable Integer id) {
        Users user = userService.getById(id);
        return  Results.ok().put("data", user);
    }


    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Results selectAll(Users user) {
        List<Users> list = userService.selectAll(user);
        return Results.ok().put("data", list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public PageResult<Users> selectPage(@RequestParam Map<String, Object> params, HttpServletRequest request){
        IPage<Users> page = userService.getUsersPage(params);
        return PageResult.success(page);
    }

}